﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WcfServer.Classes.Utility;
using System.Security.Cryptography;

namespace WcfServer.Classes.Server
{
    [Serializable]
    public class LoginData
    {
        public string UserID { set; get; }
        public string UserIP { set; get; }
        public byte[] UserSessionKey { set; get; }
        public byte[] Password { set; get; }
        public DateTime Timestamp { set; get; }

        public int listeningPort;
        public LoginData(byte[] data, string containerName)
        {
            byte[] temp = Utility.EncryptionHandler.DecryptRSA(data, containerName);
            var ld = SerializerHandler<LoginData>.DeSerializeInput(temp);
            this.UserID = ld.UserID;
            this.UserIP = ld.UserIP;
            this.UserSessionKey = ld.UserSessionKey;
            this.Password = ld.Password;
            this.Timestamp = ld.Timestamp;
            this.listeningPort = ld.listeningPort;
        }

        public LoginData() { }

        public byte[] SendUsingServerPublic(string XML)
        {
            var ld = SerializerHandler<LoginData>.SerializeInput(this);
            return EncryptionHandler.EncryptRSA_XML(ld, XML);
        }
    }
}
